package sesi.ejava.settings;

import java.util.List;

import sesi.ejava.bcam.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SettingsAdapter extends BaseAdapter {

	List<SettingsEntry> entries;
	LayoutInflater inflater;

	public SettingsAdapter(Context context,List<SettingsEntry> entries){
		inflater = LayoutInflater.from(context);
		this.entries = entries;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return entries.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return entries.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	private class ViewHolder {
		TextView setName;
		TextView setValue;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.list_item, null);
			holder.setName = (TextView)convertView.findViewById(R.id.titre);
			holder.setValue = (TextView)convertView.findViewById(R.id.description);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.setName.setText(entries.get(position).getEntryName());
		holder.setValue.setText(entries.get(position).getEntryValue());
		return convertView;
	}
}
